package com.mcy.springbatch.job;

import com.mcy.springbatch.entity.SysUser;
import com.mcy.springbatch.job.BaseJobConfig;
import com.mcy.springbatch.reader.RestartItemStreamReader;
import com.mcy.springbatch.writer.SysUserItemWriter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 读取数据异常处理
 * @author : Create By mcy
 * @date : 2019/8/25 13:06:37
 *
 */

@Slf4j
@Configuration
public class LRestartReaderJobCofig extends BaseJobConfig {

    @Autowired
    RestartItemStreamReader restartItemStreamReader;

    @Autowired
    SysUserItemWriter sysUserItemWriter;

    @Bean
    public Job restartReaderJob() {
        return jobBuilderFactory.get("restartReaderJob")
                .incrementer(new RunIdIncrementer())
                .start(restartReaderStep())
                .build();
    }
    @Bean
    public Step restartReaderStep() {
        return stepBuilderFactory.get("restartReaderStep")
                .<SysUser, SysUser>chunk(10)
                .faultTolerant()
//                .skipLimit(10)
//                .skip(Exception.class)
                .reader(restartItemStreamReader)
                .writer(sysUserItemWriter)
                .build();

    }

}
